var $;
var element;
var form;
var table;
var laydate;
var status;
var layer;

layui.use(['jquery','element','form','table','laydate','layer'],function () {
    $ = layui.$;
    element = layui.element;
    form = layui.form;
    table = layui.table;
    laydate = layui.laydate;
    layer = layui.layer;

    form.on('select(filter)', function(data){
        status = data.value;
    });

    form.on('submit(sub)', function(data){
        $.ajax({
            url:'/Department/addDept',
            data:data.field,
            type:'post',
            dataType:'json',
            success:function (data) {
                if(data.data){
                    var layer = parent.layer;
                    layer.close(layer.index);
                    layer.msg("添加成功");
                }else{
                    var layer = parent.layer;
                    layer.close(layer.index);
                    layer.msg("添加失败");
                }
            }
        });
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
});

var user = JSON.parse(localStorage.getItem("user"));
$('input[name = createId]').val(user.userId);
$('input[name = createDate]').val(timestampToTime(new Date().getTime()));
function timestampToTime(timestamp) {
    var date = new Date(timestamp);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    return Y+M+D+h+m+s;
}

function cancel() {
    var layer = parent.layer;
    layer.close(layer.index);
}